import { commerceDb } from '@/app/lib/commerce-db'; import { getCustomerUser } from '@/app/lib/lumen-auth'; import { isAdmin } from '@/app/lib/admin'; import { reviewPhotoBucket } from '@/app/lib/review-photo-storage'; import { isReviewId } from '@/app/lib/reviews'; export const dynamic = 'force-dynamic'; export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) { const { id } = await ctx.params; if (!isReviewId(id)) return new Response(null, { status: 404 }); const admin = commerceDb(); const { data: review } = await admin.from('order_reviews') .select('photo_path,status').eq('id', id).maybeSingle(); if (!review?.photo_path) return new Response(null, { status: 404 }); if (review.status !== 'approved') { const user = await getCustomerUser(); if (!isAdmin(user?.email)) return new Response(null, { status: 404 }); } const photo = await reviewPhotoBucket().get(review.photo_path); if (!photo) return new Response(null, { status: 404 }); return new Response(photo.body, { headers: { 'Content-Type': 'image/jpeg', 'Cache-Control': 'private, no-store', 'X-Content-Type-Options': 'nosniff' }, }); }